<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let str = `
      https://www.baidu.com
      http://zks.com
      `;
      let reg = /https?:\/\/((?:[\w]+\.)?[\w]+\.+(?:com|cn))/gi;
      //   ?:不记录分组意思是匹配到内容但是忽略     
      //   console.dir(str.match(/https?:\/\/([\w]+\.)?[\w]+\.+(?:com|cn)/i));

      let arr = [];
      while ((res = reg.exec(str))) {
        console.log(res);
        arr.push(res[1]);//[1]是原子组 其他的原子组被忽略了
      }
      console.log(arr);

    </script>
  </body>
</html>
